package org.nobject.common.swing.g;

import javax.swing.DefaultCellEditor;
import javax.swing.JTextField;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;

/**
 * EditableHeaderTableColumn
 * 
 * @author bianrongjun
 * @version 1.0
 */
public class GEditableHeaderTableColumn extends TableColumn {

	/** headerEditor */
	protected TableCellEditor headerEditor;

	/** isHeaderEditable */
	protected boolean isHeaderEditable;

	/**
	 * 构造函数
	 */
	public GEditableHeaderTableColumn() {
		isHeaderEditable = true;
	}

	/** setHeaderEditor */
	public void setHeaderEditor(TableCellEditor headerEditor) {
		this.headerEditor = headerEditor;
	}

	/** getHeaderEditor */
	public TableCellEditor getHeaderEditor() {
		if(headerEditor==null) headerEditor=createDefaultHeaderEditor();
		return headerEditor;
	}

	/** setHeaderEditable */
	public void setHeaderEditable(boolean isEditable) {
		isHeaderEditable = isEditable;
	}

	/** isHeaderEditable */
	public boolean isHeaderEditable() {
		return isHeaderEditable;
	}

	/** copyValues */
	public void copyValues(TableColumn base) {
		modelIndex = base.getModelIndex();
		identifier = base.getIdentifier();
		width = base.getWidth();
		minWidth = base.getMinWidth();
		setPreferredWidth(base.getPreferredWidth());
		maxWidth = base.getMaxWidth();
		headerRenderer = base.getHeaderRenderer();
		headerValue = base.getHeaderValue();
		cellRenderer = base.getCellRenderer();
		cellEditor = base.getCellEditor();
		isResizable = base.getResizable();
	}

	/** createDefaultHeaderEditor */
	protected TableCellEditor createDefaultHeaderEditor() {
		return new DefaultCellEditor(new JTextField());
	}

}
